package com.zhuss.team.processor;

import com.zhuss.bean.bo.team.question.CreateQuestionBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.team.db.dao.ext.QuestionDao;
import com.zhuss.team.db.entity.Question;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/3 14:32
 */
@Component("questionCreate")
public class QuestionCreate extends AbstractProcessor<Object, CreateQuestionBo> implements Processor<Object, CreateQuestionBo> {

    @Autowired
    private QuestionDao questionDao;

    @Override
    public Object process(CreateQuestionBo bo) throws WpsException {
        Question q = new Question();
        q.setQuestionName(bo.getQuestionName());
        q.setQuestionChoose(bo.getQuestionChoose());
        q.setInvestGroup(bo.getInvestGroup());
        q.setType(bo.getType());
        q.setSort(bo.getSort());
        q.setArea(bo.getArea());

        q.setCreator(bo.getConcurrentUserName());
        q.setCreatorId(bo.getConcurrentUserId());
        q.setCreateTime(new Date());
        questionDao.create(q);
        return null;
    }

    @Override
    public Object log(CreateQuestionBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.协同发布.key());
        record.setAction(LogActionEnum.问题创建.key());
        record.setTargetId(param.getTargetId());
        record.setTargetName(param.getQuestionName());
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }

    @Override
    public void check(CreateQuestionBo createQuestionBo) throws WpsException {

    }
}
